package net.bwie.realtime.jtp.dim.function;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.flink.api.common.functions.RichMapFunction;
import org.apache.flink.configuration.Configuration;

import java.util.Map;

public class HbaseDimMapFunction extends RichMapFunction<String,String> {

    private final Map<String, String> dimMap ;

    public HbaseDimMapFunction(Map<String, String> dimMap) {
        this.dimMap = dimMap;
    }

    @Override
    public void open(Configuration parameters) throws Exception {
        super.open(parameters);
    }

    @Override
    public String map(String value) throws Exception {
        JSONObject jsonObject = JSON.parseObject(value);

        jsonObject.put("hbase_table_name", "dim_" + jsonObject.getString("table_name"));

        jsonObject.put("family_name", "info");

        jsonObject.put("row_key_column", dimMap.get(jsonObject.getString("table_name")));

        return jsonObject.toJSONString();
    }

    @Override
    public void close() throws Exception {
        super.close();
    }
}
